﻿using RoRoWo.Data;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using NHibernate;
using RoRoWo.Domain;
using System.Collections.Generic;

using Castle.Windsor;
using Castle.Windsor.Configuration.Interpreters;

namespace RoRoWo.UnitTest
{


    /// <summary>
    ///这是 BlogCategoryRespositoryTest 的测试类，旨在
    ///包含所有 BlogCategoryRespositoryTest 单元测试
    ///</summary>
    [TestClass()]
    public class BlogCategoryRespositoryTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///获取或设置测试上下文，上下文提供
        ///有关当前测试运行及其功能的信息。
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region 附加测试特性
        // 
        //编写测试时，还可使用以下特性:
        //
        //使用 ClassInitialize 在运行类中的第一个测试前先运行代码
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //使用 ClassCleanup 在运行完类中的所有测试后再运行代码
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //使用 TestInitialize 在运行每个测试前先运行代码
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //使用 TestCleanup 在运行完每个测试后运行代码
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///Create 的测试
        ///</summary>
        [TestMethod()]
        public void CreateTest()
        {
            ////使用 Castle 的IoC
            //XmlInterpreter xmlinterpreter = new XmlInterpreter("Components.xml");
            //IWindsorContainer container = new WindsorContainer(xmlinterpreter);
            ////加入组件
            //container.AddComponent("CSession", typeof(ISession), typeof(Session));
            //ISession session = (ISession)container["CSession"];

            SessionManager sessionManager = new SessionManager();
            ISession session = sessionManager.GetSession();

            BlogCategoryRespository target = new BlogCategoryRespository(session);
            Blogcategory dto = new Blogcategory();

            dto.Catename = "新分类" + new Random().Next(100000, 999999).ToString();
            dto.Parentid = 0;
            dto.State = 0;
            dto.Createtime = DateTime.Now;

            int newid = target.CreateAndReturn(dto);
            Assert.IsTrue(newid > 0);
        }

        /// <summary>
        ///GetById 的测试
        ///</summary>
        [TestMethod()]
        public void GetByIdTest()
        {
            SessionManager sessionManager = new SessionManager();
            ISession session = sessionManager.GetSession();
            BlogCategoryRespository target = new BlogCategoryRespository(session);
            int cateId = 3;
            Blogcategory actual;
            actual = target.GetById(cateId);
            Assert.AreEqual(cateId, actual.Cateid);

        }

        /// <summary>
        ///From 的测试
        ///</summary>
        [TestMethod()]
        public void FromTest()
        {
            SessionManager sessionManager = new SessionManager();
            ISession session = sessionManager.GetSession();
            BlogCategoryRespository target = new BlogCategoryRespository(session);
            IList<Blogcategory> actual;
            actual = target.From();
            Assert.IsTrue(actual.Count > 0);

        }

        /// <summary>
        ///Select 的测试
        ///</summary>
        [TestMethod()]
        public void SelectTest()
        {
            SessionManager sessionManager = new SessionManager();
            ISession session = sessionManager.GetSession();
            BlogCategoryRespository target = new BlogCategoryRespository(session);
            IList<int> actual;
            actual = target.Select();
            Assert.IsTrue(actual.Count > 0);
        }

        /// <summary>
        ///Where 的测试
        ///</summary>
        [TestMethod()]
        public void WhereTest()
        {
            SessionManager sessionManager = new SessionManager();
            ISession session = sessionManager.GetSession();
            BlogCategoryRespository target = new BlogCategoryRespository(session);

            IList<Blogcategory> actual;
            actual = target.Where();
            Assert.IsTrue(actual.Count > 0);
        }

        /// <summary>
        ///GetGreaterThan 的测试
        ///</summary>
        [TestMethod()]
        public void GetGreaterThanTest()
        {
            SessionManager sessionManager = new SessionManager();
            ISession session = sessionManager.GetSession();
            BlogCategoryRespository target = new BlogCategoryRespository(session);
            int CateId = 0; // TODO: 初始化为适当的值
            IList<Blogcategory> actual;
            actual = target.GetGreaterThan(CateId);
            Assert.IsTrue(actual.Count > 0);

        }
    }
}
